package org.example;

import java.util.*;

class Edge {
    public int to;
    public int cost;
    Edge(int to, int cost) {
        this.to = to;
        this.cost = cost;
    }
}

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt(), M = sc.nextInt();
        List<List<Edge>> grid = new ArrayList<>(N + 1);
        for (int i = 0; i <= N; i++) {
            grid.add(new ArrayList<>());
        }
        for (int i = 0; i < M; i++) {
            int s = sc.nextInt();
            int t = sc.nextInt();
            int v = sc.nextInt();
            grid.get(s).add(new Edge(t, v));
        }

        int[] minDist = new int[N + 1];
        Arrays.fill(minDist, Integer.MAX_VALUE);
        Queue<Integer> queue = new ArrayDeque<>();
        int[] count = new int[N + 1];

        minDist[1] = 0;
        queue.offer(1);

        boolean circle = false;
        while (!queue.isEmpty() && !circle) {
            int cur = queue.poll();
            for (Edge e : grid.get(cur)) {
                if (minDist[cur] + e.cost < minDist[e.to]) {
                    minDist[e.to] = minDist[cur] + e.cost;
                    queue.add(e.to);
                    count[e.to]++;
                    if (count[e.to] >= N) {
                        circle = true;
                        break;
                    }
                }
            }
        }

        if (circle) {
            System.out.println("circle");
        } else if (minDist[N] == Integer.MAX_VALUE) {
            System.out.println("unconnected");
        } else {
            System.out.println(minDist[N]);
        }
    }
}